/**
 *  @file MessageDigest.h
 */
#ifndef _MESSAGEDIGEST_H_
#define _MESSAGEDIGEST_H_

#include "../../common/BaseObject.h"
#include "../../text/CFString.h"
#include "../../collections/ArrayT.h"

namespace cppflib
{

namespace security
{

namespace crypto
{

/**
 *  A class to generate different message digest 
 */
class _DLLAPI MessageDigest : public BaseObject
{
public:
    typedef enum _hashalgo
    {
       HA_NONE,
       HA_MD5,
       HA_SHA1,
       HA_SHA256,
       HA_SHA384,
       HA_SHA512,
    } hashalgo_t;

private:
    hashalgo_t hashAlgo;
    ptrany_t mdCtxt; 

private:
    MessageDigest(void);
    void ReleaseBeforeThrowing();

public:
    explicit MessageDigest(hashalgo_t algo);
    virtual ~MessageDigest(void);

    CFString GetHashName();
    hashalgo_t GetHashAlgorithm();
    sz_t GetHashSize();     // size in byte

    void Reinitialize();

    collections::ArrayByte * ComputeHash(collections::ArrayByte & inData);
    collections::ArrayByte * ComputeHash(collections::ArrayByte & inData, u32_t offset, u32_t count);
    
    void UpdateBlock(collections::ArrayByte & inData);
    void UpdateBlock(collections::ArrayByte & inData, u32_t offset, u32_t count);
    sz_t GetHash(collections::ArrayByte & outHash);
};

} // end of namespace crypto

} // end of namespace security

} // end of namespace cppflib

#endif

